/**
 * Class: DVector2
 *
 * Purpose: 
 *
 * Created: Jan 23, 2010 @ 11:06:19 PM
 * @author Ken Scott
 */
package org.openfantasia.util.math;

import org.openfantasia.util.Copyable;

public class DVector2 implements Copyable<DVector2> {

	private static final int N = 2;

	public double p[][];


	public DVector2() {
		p = new double[N][N];
	}


	public DVector2(double[][] p) {
		if (p[0].length != N) {
			throw new IllegalArgumentException("Input array must be of length " + N + ", not " + p[0].length);
		}
		this.p = Math2D.copy(p);
	}


	public DVector2(DVector2 p) {
		this(p.p);
	}


	public DVector2 copy() {
		return new DVector2(p);
	}


	public void copy(DVector2 that) {
		p = Math2D.copy(that.p);
	}


	public DVector2 clear() {
		Math2D.fill(p, 0);
		return this;
	}


	public DVector2 unity() {
		Math2D.fill(p, 1);
		return this;
	}


	public DVector2 identity() {
		clear();
		for (int i = 0; i < p.length; i++) {
			p[i][i] = 1;
		}
		return this;
	}


	public double[][] getValue() {
		return p;
	}


	public DVector2 setValue(double[][] v) {
		p = Math2D.copy(v);
		return this;
	}


	public DVector2 mulNoise(double frac) {
		p = Math2D.mulNoise(p, frac);
		return this;
	}


	public double get(int x, int y) {
		return p[x][y];
	}


	public DVector2 set(int x, int y, double v) {
		p[x][y] = v;
		return this;
	}


	public DVector2 addNoise(double frac) {
		p = Math2D.addNoise(p, frac);
		return this;
	}


	public DVector2 neg() {
		p = Math2D.neg(p);
		return this;
	}


	public DVector2 abs() {
		p = Math2D.abs(p);
		return this;
	}


	public DVector2 add(DVector2 a) {
		if (a == null) {
			return this;
		}

		p = Math2D.add(p, a.p);
		return this;
	}


	public DVector2 sub(DVector2 a) {
		if (a == null) {
			return this;
		}

		p = Math2D.sub(p, a.p);
		return this;
	}


	public DVector2 mul(DVector2 a) {
		if (a == null) {
			return this;
		}

		p = Math2D.mul(p, a.p);
		return this;
	}


	public DVector2 div(DVector2 a) {
		if (a == null) {
			return this;
		}

		p = Math2D.div(p, a.p);
		return this;
	}
}